package com.xiaobai.demo.mapper;

import com.xiaobai.demo.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    // 注册用户
    @Insert("INSERT INTO users(userName, password, email) VALUES(#{userName}, #{password}, #{email})")
    int register(User user);

    // 登录验证
    @Select("SELECT * FROM users WHERE userName = #{userName} AND password = #{password}")
    User login(@Param("userName") String userName, @Param("password") String password);

    // 查询所有用户
    @Select("SELECT * FROM users")
    List<User> findAll();

    // 根据 id 查询用户
    @Select("SELECT * FROM users WHERE id = #{id}")
    User findById(@Param("id") Integer id);

    // 根据用户名模糊查询用户
    @Select("SELECT * FROM users WHERE userName LIKE CONCAT('%', #{userName}, '%')")
    List<User> findByUserNameLike(@Param("userName") String userName);

    // 更新用户信息
    @Update("UPDATE users SET userName = #{userName}, password = #{password}, email = #{email} WHERE id = #{id}")
    int update(User user);

    // 删除用户
    @Delete("DELETE FROM users WHERE id = #{id}")
    int delete(@Param("id") Integer id);
}